package com.cuit.qx.controller;


import com.cuit.qx.aop.OperLog;
import com.cuit.qx.bean.AddWeatherStation;
import com.cuit.qx.service.AddWeatherStationService;
import com.cuit.qx.utils.ReturnData;
import com.cuit.qx.utils.ReturnStateCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@CrossOrigin(origins = "*", maxAge = 3600)
@RestController
@RequestMapping("/api/addSites")
public class AddWeatherStationController {

    @Autowired
    AddWeatherStationService addStationService;

    @RequestMapping(value = "/updateAddIsSure", method = RequestMethod.GET)
    @OperLog(operModul = "新增站点管理", operType = "3", operDesc = "根据id修改新增的站点确认状态")
    public ReturnData updateAddIsSure(String id) {
        int num = addStationService.updateAddIsSure(id);
        if (num > 0) {
            return new ReturnData(ReturnStateCode.SUCCEE.getCode(), ReturnStateCode.SUCCEE.getMsg(), num, new ArrayList<>());
        } else {
            return new ReturnData(ReturnStateCode.FAILED.getCode(), ReturnStateCode.FAILED.getMsg(), num, new ArrayList<>());
        }
    }

    @RequestMapping(value = "/getAddStation", method = RequestMethod.GET)
//    @OperLog(operModul = "新增站点管理", operType = "3", operDesc = "获取所有新增站点")
    public ReturnData getAddStation() {

        List<AddWeatherStation> allAddWeatherStation = addStationService.getAllAddWeatherStation();
        int num =allAddWeatherStation.size();
        if (allAddWeatherStation.size()>0) {
            return new ReturnData(ReturnStateCode.SUCCEE.getCode(), ReturnStateCode.SUCCEE.getMsg(), num, allAddWeatherStation);
        } else {
            return new ReturnData(ReturnStateCode.FAILED.getCode(), ReturnStateCode.FAILED.getMsg(), num, new ArrayList<>());
        }
    }
}
